package com.ruoyi.web.controller.student_club.admin_controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.student_club.domain.ClubType;
import com.ruoyi.student_club.service.IClubTypeService;
import com.ruoyi.student_club.vo.TypeVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 社团类型管理Controller
 * 
 * @author 无尤
 * @date 2022-01-14
 */
@Controller
@RequestMapping("/club_type/type")
public class ClubTypeController extends BaseController
{
    private String prefix = "club_type/type";

    @Autowired
    private IClubTypeService clubTypeService;

    @RequiresPermissions("club_type:type:view")
    @GetMapping()
    public String type()
    {
        return prefix + "/type";
    }

    /**
     * 查询社团类型管理列表
     */
    @RequiresPermissions("club_type:type:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ClubType clubType)
    {
        startPage();
        List<ClubType> list = clubTypeService.selectClubTypeList(clubType);
        return getDataTable(list);
    }

    /**
     * 获取社团列表
     * @return
     */
    @ResponseBody
    @GetMapping("/getTypeList")
    public AjaxResult getTypeList(){
        List<TypeVo> typeList = clubTypeService.getTypeList();
        return AjaxResult.success(typeList);
    }

    /**
     * 导出社团类型管理列表
     */
    @RequiresPermissions("club_type:type:export")
    @Log(title = "社团类型管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ClubType clubType)
    {
        List<ClubType> list = clubTypeService.selectClubTypeList(clubType);
        ExcelUtil<ClubType> util = new ExcelUtil<ClubType>(ClubType.class);
        return util.exportExcel(list, "社团类型管理数据");
    }

    /**
     * 新增社团类型管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存社团类型管理
     */
    @RequiresPermissions("club_type:type:add")
    @Log(title = "社团类型管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ClubType clubType)
    {
        return toAjax(clubTypeService.insertClubType(clubType));
    }

    /**
     * 修改社团类型管理
     */
    @RequiresPermissions("club_type:type:edit")
    @GetMapping("/edit/{typeId}")
    public String edit(@PathVariable("typeId") Integer typeId, ModelMap mmap)
    {
        ClubType clubType = clubTypeService.selectClubTypeByTypeId(typeId);
        mmap.put("clubType", clubType);
        return prefix + "/edit";
    }

    /**
     * 修改保存社团类型管理
     */
    @RequiresPermissions("club_type:type:edit")
    @Log(title = "社团类型管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ClubType clubType)
    {
        return toAjax(clubTypeService.updateClubType(clubType));
    }

    /**
     * 删除社团类型管理
     */
    @RequiresPermissions("club_type:type:remove")
    @Log(title = "社团类型管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(clubTypeService.deleteClubTypeByTypeIds(ids));
    }
}
